package com.example.common

import android.annotation.SuppressLint
import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route

import com.example.room.AppDabase
import com.kongzue.dialogx.dialogs.WaitDialog

import com.tencent.mmkv.MMKV


@Route(path = "/app/MMKVUtils")
class MMKVUtils {
    companion object{
        private var context: Context? = null
        private var mmkv: MMKV? =null
        fun init(c:Context){
            MMKV.initialize(c)
            MMKVUtils.context = c
            mmkv = MMKV.defaultMMKV()!!
        }

        public fun putString (key:String, string:String){
            mmkv!!.putString(key,string)
        }
        public fun getString (key:String, string:String): String? {
            return mmkv!!.getString(key,string)
        }



        public suspend fun putUser(user: User) {
            val useDAO = context.let { it?.let { it1 -> AppDabase.getInstance(it1).UserDAO() } }
                useDAO!!.insertAll(user)
        }


        fun putString(cookie: String, cookies: HashSet<String>) {
            mmkv!!.putStringSet(cookie,cookies)
        }
    }
}